//


#import "MB_TabBarController.h"
#import "MB_SetUpViewController.h"
#import "MB_FirstViewController.h"
#import "MB_AddViewController.h"
#import "MB_ReadViewController.h"
#import "MB_DietViewController.h"

@interface MB_TabBarController ()

@end

@implementation MB_TabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self createTabBar];//创建标签栏
    [self createSubviewControllers];//创建子控制器
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tabbarHide) name:@"tabbarHide" object:nil];//观察隐藏tabbar
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tabbarShow) name:@"tabbarShow" object:nil];//观察显示tabbar
    
}
//隐藏tabbar
- (void)tabbarHide{
    self.myTabBar.hidden = YES;
}
//显示tabbar
- (void)tabbarShow{
    self.myTabBar.hidden = NO;
}

//创建标签栏
- (void)createTabBar{
    self.tabBar.hidden = YES;
    
    NSArray * imgNormal = @[@"home",@"read3",@"time", @"set"];
    NSArray * imgSelected = @[@"home1",@"read4",@"time1", @"set1"];
    NSArray * buttonTitle = @[@"Home",@"Read",@"Diet", @"Personal"];
    
    __weak typeof(self) weakself=self;
    NSDictionary * dic = [[NSDictionary alloc]initWithObjectsAndKeys:imgNormal,@"imageNameNormal",imgSelected,@"imageNameSelected",buttonTitle,@"buttonTitle", nil];
    self.myTabBar = [[MB_MyTabBar alloc]initWithFrame:CGRectMake(0,kMainScreenHeight-UI_TAB_BAR_HEIGHT,kMainScreenWidth, UI_TAB_BAR_HEIGHT) andTabBarButtonDictory:dic andBlock:^(NSInteger index) {
        weakself.selectedIndex = index;
        
    }];
    self.myTabBar.delegate = self;
    [self.view addSubview:self.myTabBar];
    
}

//构建子视图控制器
- (void)createSubviewControllers{
    
    //创建子控制器
    MB_FirstViewController * v1 = [[MB_FirstViewController alloc] init];
    MB_ReadViewController *v2 = [[MB_ReadViewController alloc]init];
    MB_DietViewController *v3 = [[MB_DietViewController alloc]init];
    MB_SetUpViewController *v4 = [[MB_SetUpViewController alloc] init];//
    //创建子控制器的导航栏控制器
    UINavigationController *nv1 = [[UINavigationController alloc] initWithRootViewController: v1];
    UINavigationController *nv2 = [[UINavigationController alloc] initWithRootViewController: v2];
    UINavigationController *nv3 = [[UINavigationController alloc] initWithRootViewController: v3];
    UINavigationController *nv4 = [[UINavigationController alloc] initWithRootViewController: v4];
    self.viewControllers =@[nv1,nv2,nv3,nv4];
    
}
//
-(void)mbSpecailButtonClickAction {
    MB_AddViewController *vc = [[MB_AddViewController alloc]init];
    UINavigationController *nvc = [[UINavigationController alloc]initWithRootViewController:vc];
    vc.height = UI_NAV_BAR_HEIGHT;
    [self presentViewController:nvc animated:YES completion:nil];
    
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
